/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BO;

import java.util.List;
import java.util.Vector;

/**
 *
 * @author olivierm
 */
public class ListeEmploye {
   
    //*******************************************************************
    //Variables
    //*******************************************************************
    
    private static ListeEmploye instance;
    private List<Employe> _listeEmploye;

    //*******************************************************************
    //Constructeurs
    //*******************************************************************
    
    private ListeEmploye(){
        this._listeEmploye = new Vector<Employe>();
    }  
 /**
 * Methodes pour le singleton
 */
    public static ListeEmploye getInstance(){
        if(instance == null) {
            instance = new ListeEmploye();
        }
        return instance;
    }
    
    //*******************************************************************
    //Getters et Setters
    //*******************************************************************
    public synchronized List<Employe> get_listeEmploye() {
        return _listeEmploye;
    }

    public synchronized void set_listeEmploye(List<Employe> _listeEmploye) {
        this._listeEmploye = _listeEmploye;
    }
     
    //*******************************************************************
    //Méthode d'instance
    //******************************************************************* 
    
    public synchronized boolean ajouterEmploye(Employe employe){
        if (employe != null){
            this._listeEmploye.add(employe);
            return true;
        }
        return false;
    }
    
    public synchronized boolean supprimerEmploye(Employe employe){
        if (employe != null){
            this._listeEmploye.remove(employe);
            return true;
        }
        return false;
    }
    
    public synchronized Vector<Employe> rechercherEmploye(String nom, String prenom){
        if((nom != null)||(prenom != null)){
            Vector<Employe> listeTmp = new Vector<Employe>();
            for (int i = 0; i < this._listeEmploye.size(); i++){
                Employe employe = this._listeEmploye.get(i);
                if ((employe.getNom().compareTo(nom) == 0) && (employe.getPrenom().compareTo(prenom) == 0)){
                    listeTmp.add(employe);
                }
            }
            return listeTmp;
        }
        return null;
    }
    
    public synchronized Employe rechercherEmploye(String matricule){
        if (matricule != null){
            for(int i = 0; i < this._listeEmploye.size(); i++){
                Employe employe = this._listeEmploye.get(i);
                if (employe.get_matricule().compareTo(matricule) == 0)
                    return employe;
            }
        }
        return null;
    }

    //*******************************************************************
    //Méthode de classe
    //*******************************************************************
    
}
